package com.dx.financehy.modules.business.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dx.financehy.modules.business.domain.Business;
import com.dx.financehy.modules.business.mapper.BusinessMapper;
import com.dx.financehy.modules.business.mapper.BusinessTwoMapper;
import com.dx.financehy.modules.business.service.BusinessService;
import com.dx.financehy.modules.system.domain.vo.BusinessTwoVO;
import com.dx.financehy.modules.system.domain.vo.BusinessVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: huang_jigao
 * @Title: BusinessServiceImpl
 * @ProjectName: financehy
 * @Description:
 * @date: 2024-05-16 8:50
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business> implements BusinessService {

    private final BusinessMapper mapper;

    private final BusinessTwoMapper businessTwoMapper;

    /**
     * 移动端首页
     *
     * @param userId
     * @return
     */
    @Override
    public List<BusinessVO> getBusinessHomePage(String userId){
        List<BusinessVO> list = mapper.getBusinessHomePage(userId);

        if (CollectionUtil.isNotEmpty(list)){
            List<String> businessIds = list.stream().map(m->m.getBusinessId()).collect(Collectors.toList());
            List<BusinessTwoVO> twoVOS = businessTwoMapper.getEditBusinessList(businessIds);

            if (CollectionUtil.isNotEmpty(twoVOS)){
                list.stream().forEach(u->{
                    u.setTwoVOS(twoVOS.stream().filter(f->f.getClassOneId().equals(u.getBusinessId())).collect(Collectors.toList()));
                });
            }
        }
        return list;
    }
}
